const connection = require("../app/database")

class FileService {
  // 创建头像相关信息
  async create(filename, mimetype, size, id) {
    const statement =
      "INSERT INTO avatar (filename, mimetype, size, user_id) VALUES (?, ?, ?, ?);"
    const [res] = await connection.execute(statement, [
      filename,
      mimetype,
      size,
      id,
    ])
    return res
  }

  // 用过用户id查询头像
  async queryAvatarWithUserId(userId) {
    const statement = "SELECT * FROM avatar WHERE user_id = ?;"
    const [result] = await connection.execute(statement, [userId])
    // @ts-ignore
    return result.pop()
  }

  
}

module.exports = new FileService()
